﻿@model mock_ehr_web.Models.PatientQualityReport
           
<p>The following represent quality measures associated with this patient.</p>
@foreach (var category in Model.Categories)
{
    <h3>@category</h3>
   
    if (Model.Items == null)
   {
       <div class="message">
                No eligible measures identified in this category
       </div>
       continue;
   }
   else
   {
       var qualityItems = Model.Items.Where(i => i.Measure.Category == category);
       if (!qualityItems.Any())
       {
           <div class="message">
                No eligible measures identified in this category
            </div>
       }
    <ul id="measures">
        @foreach (var qualityItem in qualityItems)
        {
            <li class='@(qualityItem.Result.Evaluation ? "pass" : "fail")'>
                <table>
                    <tr>
                        <td>
                            <span class="infobutton" data-infobutton-url="@qualityItem.Measure.InfoUrl" title="infobutton">
                                infobutton</span>
                        </td>
                        <td>
                            <div class="question">@qualityItem.Measure.Question</div>
                        </td>
                    </tr>
                </table>
                <div class="message">@qualityItem.Result.Message</div>
                <div>
                    @if (!qualityItem.Result.Evaluation)
                    {
                        if (qualityItem.Measure.Category == "Structure")
                        {
                            @Html.ActionLink("Enter", "Create", "Social", new { }, new { @class = "social button", @data_nqf_no = @qualityItem.Measure.NqfNo })
                        }
                        else
                        {
                        <div style="display:none">
                            <label>
                                @Html.RadioButton(qualityItem.Measure.NqfNo, "Y", qualityItem.Result.Evaluation)
                                Yes
                            </label>
                            <label>
                                @Html.RadioButton(qualityItem.Measure.NqfNo, "N", !qualityItem.Result.Evaluation)
                                No
                            </label>
                        </div>
                        @Html.ActionLink("Order", "Create", "Order", new { }, new { @class = "order button", @data_nqf_no = @qualityItem.Measure.NqfNo })
                        }
                    }
                </div>
            </li>
        }
    </ul>
   }
}
<script language="javascript" type="text/javascript">
    $.fn.serializeObject = function()
    {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
    $(function () {
        $(".button").button();
        $(".button").click(function () {
            var self = $(this);
            var nqfNo = self.attr("data-nqf-no");
            var href = self.attr("href");
            var actionType = self.hasClass("social") ? "Social" : "Order";
            $.ajax({
                url: href,
                data: { "nqfNo" : nqfNo },
                success: function (html) {
                    var form = $("<form>"+html+"</form>");
                    var buttons = {};
                    buttons["Submit"] = function(){
                            $.ajax({
                                url : '@Url.Content("~")'+actionType+"/Submit",
                                data: form.serializeObject(),
                                success: function(r) { 
                                    form.dialog("close"); 
                                    $(r).dialog({
                                        title: "Success"
                                    });
                                    var tabs = $("#tabs");
                                    tabs.tabs('load', tabs.tabs('option', 'selected'));
                                }
                            });
                    };
                    form.dialog({
                        title: "Add " + actionType + " Item",
                        modal: true,
                        buttons: buttons,
                        width: "400px"
                    });
                },
            });
            return false;
        });
    });
</script>
